<?php
# $Id: DefaultIndexAction.class.php,v 1.2 2006/06/22 14:41:15 diegor Exp $
require_once(APP_LIB_DIR . 'LoginModel.class.php');
require_once(APP_LIB_DIR . 'MessagingModel.class.php');
include_once(APP_LIB_DIR . 'JSON.php');
Class InquiryAction Extends Action
{
    function getDefaultView(&$controller, &$request, &$user)
    { 
        return VIEW_INPUT;
    }

    function getRequestMethods()
    {
        return REQ_POST | REQ_GET;
    }

    function IsSecure()
    {
        return false;
    }

    function getPrivilege (&$controller, &$request, &$user)
    {
        return Array('INQUIRY');
    }

    function getparameters($request)
    {
        $param = array();
        $param['flag'] = $request->getParameter('flag');
        $param['mod'] = $request->getParameter('mod');

        return $param;
    }

    function execute(&$controller, &$request, &$user)
    {
		$auth = $user->getAttribute('auth');
		$GLOBALS['login'] = $auth['username'];
		$GLOBALS['user_id'] = $auth['id'];
		$GLOBALS['user_privilege'] = $auth['privilege'];
        return VIEW_INPUT;
    }
	function save($detail,$to,$msg,$smsc,$action)
	{
                $mm = new MessagingModel('Messaging');
//		$sm     = new OutboxManagerModel('OutboxManagerAction');
		$json   = new Services_JSON();

		if ($action == "get"){
			return $json->encode($sm->detail($id));
		}elseif ($action == "del"){
			//return $json->encode($sm->deactivate($id));
			$detail['modified_by'] = $GLOBALS['login'];
			$detail['active']      = 0;
			$detail['modified_date'] = "NOW()";
			return $json->encode($sm->edit($id,$detail));
		}elseif ($action == "send_msg"){
			//return $json->encode($sm->deactivate($id));
                        $member_id='';
                        $group_id='';
//                        $smsc = $detail['smsc'];
//                        $smsc = ($smsc=='auto') ? false : $smsc;
    		       //return $json->encode($mm->send_sms($detail['to'], $detail['message'],$smsc,$GLOBALS['login']));
    		       return $json->encode($mm->send_sms($to, $msg,$smsc,$GLOBALS['login'],$member_id,$group_id));
		}elseif ($id){
			$detail = $this->change_case($detail['details']);
			$detail['modified_by'] = $GLOBALS['login'];
			return $json->encode($sm->edit($id,$detail));
		}else{
			$detail = $this->change_case($detail['details']);
			$detail['auth_id'] = $GLOBALS['user_id'];
			$detail['created_by'] = $GLOBALS['login'];
			$detail['creation_date'] = "NOW()";
			return $json->encode($sm->ins($detail));
		}
	}
}
?>
